package cn.tedu.medicalappointmentsystemk.controller;


import cn.tedu.medicalappointmentsystemk.pojo.bo.PatientSelectBO;
import cn.tedu.medicalappointmentsystemk.pojo.bo.PatientSelectDetailBO;
import cn.tedu.medicalappointmentsystemk.pojo.param.PatientUpdateParam;
import cn.tedu.medicalappointmentsystemk.pojo.po.PageData;
import cn.tedu.medicalappointmentsystemk.response.JsonResult;
import cn.tedu.medicalappointmentsystemk.service.PatientService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("v1/patients")
@Slf4j
@Api(tags = "患者模块")
public class PatientController {
    @Autowired
    PatientService patientService;

    @GetMapping("{id}/select")
    @PreAuthorize("hasAuthority('/patients/select')")
    @ApiOperationSupport(order = 410)
    @ApiOperation("查询用户信息")
    public JsonResult patientDetail(@PathVariable Long id){
        log.info("开始执行根据id:[{}]查询用户信息功能",id);
        PatientSelectDetailBO detailBO = patientService.patientDetail(id);
        log.info("执行根据id:[{}]查询用户信息功能结束,出参:{}",id,detailBO);
        return JsonResult.ok(detailBO);
    }
    @GetMapping("select-type/pageNum={pageNum}")
    @PreAuthorize("hasAuthority('/patients/select')")
    @ApiOperationSupport(order = 420)
    @ApiOperation("查询全部用户信息(用于在管理界面显示)")
    public JsonResult patientSelect(@PathVariable Integer pageNum){
        log.info("开始执行查询用于在管理界面显示的全部用户信息功能");
        PageData<PatientSelectBO> pageData = patientService.patientSelect(pageNum);
        log.info("执行查询用于在管理界面显示的全部用户信息功能结束,出参:{}",pageData);
        return JsonResult.ok(pageData);
    }
    @PostMapping("{id}/delete")
    @PreAuthorize("hasAuthority('/patients/delete')")
    @ApiOperationSupport(order = 430)
    @ApiOperation("删除用户")
    public JsonResult patientDelete(@PathVariable Long id){
        log.info("开始执行根据id:[{}]删除用户功能",id);
        patientService.patientDelete(id);
        log.info("执行根据id:[{}]删除用户功能结束",id);
        return JsonResult.ok();
    }
    @PostMapping("update")
    @PreAuthorize("hasAuthority('/patients/update')")
    @ApiOperationSupport(order = 440)
    @ApiOperation("更新用户信息")
    public JsonResult patientUpdate(PatientUpdateParam param){
        log.info("开始执行更新用户信息功能,入参:{}",param);
        patientService.patientUpdate(param);
        log.info("执行更新用户信息功能结束");
        return JsonResult.ok();
    }
    @GetMapping("searchLastWeek/{pageNum}")
    @PreAuthorize("hasAuthority('/patients/select')")
    @ApiOperationSupport(order = 450)
    @ApiOperation("查询最近7天内注册的患者")
    public JsonResult searchLastWeek(@PathVariable Integer pageNum){
        PageData<PatientSelectBO> pageData = patientService.searchLastWeek(pageNum);
        return JsonResult.ok(pageData);
    }
    @GetMapping("searchLastMonth/{pageNum}")
    @PreAuthorize("hasAuthority('/patients/select')")
    @ApiOperationSupport(order = 450)
    @ApiOperation("查询最近30天内注册的患者")
    public JsonResult searchLastMonth(@PathVariable Integer pageNum){
        PageData<PatientSelectBO> pageData = patientService.searchLastMonth(pageNum);
        return JsonResult.ok(pageData);
    }

    @GetMapping("searchToday/{pageNum}")
    @PreAuthorize("hasAuthority('/patients/select')")
    @ApiOperationSupport(order = 450)
    @ApiOperation("查询今天内注册的患者")
    public JsonResult searchToday(@PathVariable Integer pageNum){
        PageData<PatientSelectBO> pageData = patientService.searchToday(pageNum);
        return JsonResult.ok(pageData);
    }
    @GetMapping("selectByNickname/{nickname}")
    @PreAuthorize("hasAuthority('/patients/select')")
    @ApiOperationSupport(order = 420)
    @ApiOperation("查询全部用户信息(用于在管理界面显示)")
    public JsonResult patientSelect(@PathVariable String nickname){
        log.info("开始执行查询用于在管理界面显示的全部用户信息功能");
        List<PatientSelectBO> pageData = patientService.patientSelect(nickname);
        log.info("执行查询用于在管理界面显示的全部用户信息功能结束,出参:{}",pageData);
        return JsonResult.ok(pageData);
    }

}